﻿// 项目：	Guan.CMS.Domain - Guan.CMS
// 文件名：	UpdateHitsHandler.cs
// 
// 修改时间：2013-03-09 22:04
// 修改人：	Cooclsee

using Guan.CMS.CommandProcessor.Command;
using Guan.CMS.Data.Infrastructure;
using Guan.CMS.Data.Repositories;
using Guan.CMS.Domain.Commands.Article;

namespace Guan.CMS.Domain.Handlers.Article
{
    public class UpdateHitsHandler : ICommandHandler<UpdateHitsCommand>
    {
        private readonly IArticleRepository _articleRepository;
        private readonly IUnitOfWork _unitOfWork;

        public UpdateHitsHandler(IArticleRepository articleRepository, IUnitOfWork unitOfWork)
        {
            this._articleRepository = articleRepository;
            this._unitOfWork = unitOfWork;
        }

        public ICommandResult Execute(UpdateHitsCommand command)
        {
            var post = _articleRepository.GetById(command.Id);
            post.Hits++;
            _articleRepository.Update(post);
            return new CommandResult(true);
        }
    }
}